import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;

public class O30 {

    Stack<Integer> stack;
    Stack<Integer> min;
    public O30() {
        stack = new Stack();
        min = new Stack();
    }

    public void push(int x) {
        stack.push(x);
        if (min.isEmpty()) {
            min.push(x);
        } else {
            Integer pop = min.pop();
            if (x > pop) {
                min.push(pop);
                min.push(pop);
            } else {
                min.push(pop);
                min.push(x);
            }
        }
    }

    public void pop() {
        stack.pop();
        min.pop();
    }

    public int top() {
        Integer pop = stack.pop();
        stack.push(pop);
        return pop;
    }

    public int min() {
        Integer pop = min.pop();
        min.push(pop);
        return pop;

    }
}

